package github.fafaovo.common.gui;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import github.fafaovo.common.config.exampleconfig;
import github.fafaovo.deepcapacity;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TranslationTextComponent;

public class ExampleHUD extends AbstractGui {
    public static final ResourceLocation TEXTURES =
            new ResourceLocation(deepcapacity.MOD_ID,"textures/gui/example_gui_2.png");
    private final int width;
    private final int hegith;
    private final Minecraft minecraft;
    private MatrixStack matrixStack;

    public ExampleHUD(MatrixStack matrixStack) {
        this.width = Minecraft.getInstance().getMainWindow().getWidth();
        this.hegith = Minecraft.getInstance().getMainWindow().getHeight();
        this.minecraft = Minecraft.getInstance();
        this.matrixStack = matrixStack;
    }

    public void setMatrixStack(MatrixStack matrixStack) {
        this.matrixStack = matrixStack;
    }

    //渲染图像方法
    public void render(float power)
    {

        int h = exampleconfig.power_h.get();
        int w = exampleconfig.power_w.get();
        //清空画笔
        RenderSystem.color4f(1.0f,1.0f,1.0f,1.0f);
        //绑定贴图
        this.minecraft.getTextureManager().bindTexture(TEXTURES);
        //渲染贴图
        blit(matrixStack,w,h,0,0,100,8);
        //渲染进度条
        blit(matrixStack,w + 3,h + 2,0,8,
                ratio(94,exampleconfig.max_power.get(),power),4);


        if(exampleconfig.power_name_boolean.get())
        {
            //渲染文字 字体 文字
            drawCenteredString(matrixStack,minecraft.fontRenderer,
                    new TranslationTextComponent(exampleconfig.power_name.get() + " : " + (int)power) ,
                    w + 5 + 40,
                    h + 8 + 2,
                    0xffffff);//宽度 高度
        }
        else
        {
            //渲染文字 字体 文字
            drawCenteredString(matrixStack,minecraft.fontRenderer,
                    new TranslationTextComponent(deepcapacity.MOD_ID + ".power:", (int)power) ,
                    w + 5 + 40,
                    h + 8 + 2,
                    0xffffff);//宽度 高度
        }




    }

    public int ratio(double mapDist,double actDist,double atp)
    {
        if(actDist == 0)
            return 0;
        return (int) (mapDist / actDist * atp);
    }
}
